package main

import (
	"fmt"
	"reflect"
	"runtime"
	"time"
)

func foo() {
	fmt.Println("foo is running")
	time.Sleep(time.Second * 1)
}
func bar() {
	fmt.Println("bar is running")
	time.Sleep(time.Second * 1)
}

func FuncTimer(f func()) func() {
	return func() {
		startTime := time.Now().Unix()
		f()
		endTime := time.Now().Unix()
		fn := runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
		fmt.Printf("%s函数执行的时间为：%ds\n", fn, endTime-startTime)
	}
}
func main() {
	foo := FuncTimer(foo)
	foo()
}
